package sanglh.edu.hsphysics.main;

import sanglh.edu.hsphysics.formulas.FormulaItem;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

public abstract class FragmentNavigationDrawerItem extends Fragment implements
		OnItemClickListener {
	protected FormulaCallbacks mCallbacks;

	public abstract String getTitle();

	@Override
	public void onAttach(Activity activity) {
		((MenuActivity) activity).onSectionAttached(getTitle());
		super.onAttach(activity);
		try {
			mCallbacks = (FormulaCallbacks) activity;
		} catch (ClassCastException e) {
			throw new ClassCastException(
					"Activity must implement NavigationDrawerCallbacks.");
		}
	}

	/**
	 * Callbacks interface that all activities using this fragment must
	 * implement.
	 */
	public static interface FormulaCallbacks {
		/**
		 * Called when an item in the navigation drawer is selected.
		 */
		void onFormularSelected(FormulaItem item);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		FormulaItem item = (FormulaItem) parent.getAdapter().getItem(position);
		if (mCallbacks != null) {
			mCallbacks.onFormularSelected(item);

		}

	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		setHasOptionsMenu(true);
		super.onCreate(savedInstanceState);
	}

}
